package com.navinfo.navigation.layers;

import android.widget.Toast;

import org.oscim.core.GeoPoint;
import org.oscim.event.Gesture;
import org.oscim.event.GestureListener;
import org.oscim.event.MotionEvent;
import org.oscim.layers.Layer;
import org.oscim.map.Map;

public class MapEventsReceiver extends Layer implements GestureListener {
    private MapGuestureListener mapGuestureListener;
    public MapEventsReceiver(Map map, MapGuestureListener mapGuestureListener) {
        super(map);
        this.mapGuestureListener = mapGuestureListener;
    }

    @Override
    public boolean onGesture(Gesture g, MotionEvent e) {
        if (g instanceof Gesture.Tap) {
            GeoPoint p = mMap.viewport().fromScreenPoint(e.getX(), e.getY());
            if (mapGuestureListener!=null) {
                mapGuestureListener.onTap(p);
            }
            return true;
        }
        if (g instanceof Gesture.LongPress) {
            GeoPoint p = mMap.viewport().fromScreenPoint(e.getX(), e.getY());
            if (mapGuestureListener!=null) {
                mapGuestureListener.onLongPress(p);
            }
            return true;
        }
        if (g instanceof Gesture.TripleTap) {
            GeoPoint p = mMap.viewport().fromScreenPoint(e.getX(), e.getY());
            if (mapGuestureListener!=null) {
                mapGuestureListener.onTripleTap(p);
            }
            return true;
        }
        return false;
    }

    public interface MapGuestureListener {
        void onTap(GeoPoint geoPoint);
        void onLongPress(GeoPoint geoPoint);
        void onTripleTap(GeoPoint geoPoint);
    }
}
